package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.annos.OperateLog;
import com.tbit.common.constant.MethodEnum;
import com.tbit.common.constant.ModuleEnum;
import com.tbit.uqbike.manager.exception.BaseException;
import com.tbit.uqbike.object.pojo.FestivalActivity;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.FestivalActivityService;
import com.tbit.uqbike.webmanager.util.Assert;
import com.tbit.uqbike.webmanager.util.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: chen
 * @Description: 节日赠送配置
 * @Date: 创建于 14:21 2020/6/5
 */
@RestController
@RequestMapping("/festivalActivity")
public class FestivalActivityController {
    @Autowired
    private FestivalActivityService festivalActivityService;

    /**
     * 分页
     *
     * @param accountId
     * @param pageNO
     * @param rowCount
     * @return
     */
    @RequestMapping("/queryPage")
    public JsonResult queryPage(Integer accountId, @RequestParam(defaultValue = "1") Integer pageNO, @RequestParam(defaultValue = "10") Integer rowCount) {
        List<FestivalActivity> list = festivalActivityService.queryPage(accountId, pageNO, rowCount);
        Integer total = festivalActivityService.queryCount(accountId);
        return JsonResult.ok(list, total);
    }

    /**
     * 新增
     *
     * @param festivalActivity
     * @return
     */
    @RequestMapping("/add")
    @OperateLog(module = ModuleEnum.FESTIVALACTIVITY, methods = MethodEnum.FESTIVALACTIVITY_ADD)
    public JsonResult add(FestivalActivity festivalActivity) {
        LogUtil.info("收到参数" + festivalActivity);
        Assert.notNull(festivalActivity.getAccountId(), "ver.adAccountId.notNull");
        if (festivalActivity.getCouponId() == null || festivalActivity.getGiveMoney() == null) {
            throw new BaseException("ver.giveMoney.notNull");
        }
        Assert.notNull(festivalActivity.getFestivalType(), "ver.festivalType.notNull");
        Assert.notNull(festivalActivity.getFestivalDays(), "ver.festivalDays.notNull");
        Assert.notNull(festivalActivity.getName(), "ver.name.notNull");
        if (festivalActivity.getCouponId() != null) {
            Assert.notNull(festivalActivity.getCouponCount(), "ver.couponCount.notNull");
            Assert.notNull(festivalActivity.getValidDays(), "ver.validDays.notNull");
        }
        festivalActivityService.insert(festivalActivity);
        return JsonResult.ok();
    }

    /**
     * 删除
     *
     * @param festivalactivityId
     * @return
     */
    @RequestMapping("/del")
    @OperateLog(module = ModuleEnum.FESTIVALACTIVITY, methods = MethodEnum.FESTIVALACTIVITY_DEL)
    public JsonResult del(Integer festivalactivityId) {
        Assert.notNull(festivalactivityId, "ver.applyId.notnull");
        festivalActivityService.del(festivalactivityId);
        return JsonResult.ok();
    }

}
